package com.ag.zhh.service;

import javax.annotation.Resource;

import com.ag.bean.TbCtiIp;
import com.ag.dao.TbCtiIpDAO;
import com.ag.dao.TbUserDAO;

public class CTIService {
	
	@Resource(name="TbCtiIpDAO")
	private TbCtiIpDAO ctiIpDAO;
	
	@Resource(name="TbUserDAO")
	private TbUserDAO userDAO;
	
	/**
	 * 获取cti服务器IP地址
	 * @return
	 */
	public String getCtiIp() {
		TbCtiIp ctiIp = null;
		ctiIp = ctiIpDAO.findById("ctiIP");
		if(ctiIp == null ) {
			ctiIp = addCtiIp();
			return ctiIp.getA();
		}
		
		return ctiIp.getA();
	}
	
	/**
	 * 更新cti服务器IP地址
	 * @param newCtiIp 新的cti服务器IP地址
	 * @return
	 */
	public String updateCtiIp(String newCtiIp) {
		TbCtiIp ctiIp = ctiIpDAO.findById("ctiIP");
		if(ctiIp == null ) {
			ctiIp = addCtiIp();
		}
		ctiIp.setA(newCtiIp);
		ctiIpDAO.attachDirty(ctiIp);
		return ctiIp.getA();
	}
	
	private TbCtiIp addCtiIp() {
		TbCtiIp ctiIp = new TbCtiIp();
		ctiIp.setCtiIp("ctiIP");
		ctiIp.setA("127.0.0.1");
		ctiIpDAO.attachDirty(ctiIp);
		return ctiIp;
	}
	
	
}
